package com.zuoyy.admin.system.service;

import com.zuoyy.admin.common.component.shiro.ShiroUtil;
import com.zuoyy.modules.system.domain.Role;
import com.zuoyy.modules.system.domain.User;
import com.zuoyy.modules.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class BaseInterface {

    @Autowired
    private UserService userService;

    protected Map<String, Object> setQueryResult(int draw, int rowCount, List<?> records) {
        Map<String, Object> resmap = new HashMap<String, Object>();
        resmap.put("draw", draw);
        resmap.put("recordsTotal", rowCount);
        resmap.put("recordsFiltered", rowCount);
        resmap.put("data", records);
        return resmap;
    }

    protected User getUser(){
        return userService.getUserDetail(ShiroUtil.getSubject().getId());
    }

    protected Role getUserRole(){
        return userService.getUserDetail(ShiroUtil.getSubject().getId()).getRoles().stream().findFirst().orElse(null);
    }


}
